import { faker } from '@faker-js/faker';
import { Event } from 'src/modules/event/entities/event.entity';
import { EventTypeEnum } from 'src/common/constant/enums';

// 定义 Event 的可选参数类型
type PartialEvent = Partial<Event>;

// 生成单个 Event 模拟数据的函数，允许传入部分数据
export function generateEventMock(override?: PartialEvent): Event {
  const event = new Event();
  event.id = override?.id ?? faker.number.int();
  event.name = override?.name ?? faker.lorem.words();
  event.type = override?.type ?? faker.helpers.enumValue(EventTypeEnum);
  event.fee = override?.fee ?? faker.number.float({ min: 0, max: 1000 });
  event.minPlayerCount =
    override?.minPlayerCount ?? faker.number.int({ min: 1, max: 100 });
  event.maxPlayerCount =
    override?.maxPlayerCount ??
    faker.number.int({ min: event.minPlayerCount, max: 200 });
  event.createBy = override?.createBy ?? faker.number.int();
  event.createTime = override?.createTime ?? faker.date.past();
  event.updateBy = override?.updateBy ?? faker.number.int();
  event.updateTime = override?.updateTime ?? faker.date.recent();
  event.eventToPlayers = override?.eventToPlayers ?? [];
  event.playerSignups = override?.playerSignups ?? [];
  event.category = override?.category ?? undefined;
  event.categoryId = override?.categoryId ?? faker.number.int();
  event.stages = override?.stages ?? [];
  event.tournamentId = override?.tournamentId ?? faker.number.int();
  event.tournament = override?.tournament ?? undefined;

  return event;
}

// 生成多个 Event 模拟数据的函数
export function generateEventMocks(
  count: number,
  overrides?: PartialEvent[],
): Event[] {
  return Array.from({ length: count }, (_, index) =>
    generateEventMock(overrides?.[index]),
  );
}
